%% This is a simple module.

-module(my_module).
-record(customer, {name="<anonymous>", address, phone}).
-export([pie/0, print/1, either_or_both/2, make_customer/2,
        do_sum/1, reverse_list/1, rev/1]).

pie() ->
    3.14.

print(Term) ->
    io:format("The value of Term is: ~p.~n", [Term]).

either_or_both(true, B) when is_boolean(B) ->
    true;
either_or_both(A, true) when is_boolean(A) ->
    true;
either_or_both(false, false) ->
    false.

make_customer(Name, Phone) ->
    #customer{name=Name, phone=Phone}.

do_sum_iter(0, Acc) ->
    Acc;
do_sum_iter(N, Acc) ->
    do_sum_iter(N-1, Acc+N).
do_sum(N) ->
    do_sum_iter(N, 0).

reverse_list([], Acc) ->
    Acc;
reverse_list([Car | Cdr], Acc) ->
    reverse_list(Cdr, [Car | Acc]).
reverse_list(L) ->
    reverse_list(L, []).

rev([]) ->
    [];
rev([A]) ->
    [A];
rev([Car, Cadr | Cddr]) ->
    rev(Cddr) ++ [Cadr, Car].
